import { Component } from '@angular/core';
import { NavController, NavParams, ToastController, LoadingController } from 'ionic-angular';
import { BaseUI } from '../../common/baseui';
import { Storage } from '@ionic/storage';
import { RestProvider } from '../../providers/rest/rest';
import { DetailsPage } from '../details/details';


@Component({
  selector: 'page-notification',
  templateUrl: 'notification.html',
})
export class NotificationPage extends BaseUI {
  errorMessage: any;
  notificationList: string[];
  show:boolean;
  constructor(
    public navCtrl: NavController,
    public navParams: NavParams,
    private toastCtrl: ToastController,
    private loadingCtrl: LoadingController,
    private storage: Storage,
    private rest: RestProvider) {
    super();
  }

  ionViewDidLoad() {
    this.storage.get('UserId').then((val) => {
      if (val != null) {
        //加载用户数据
        var loading = super.showLoading(this.loadingCtrl, "加载中...");
        this.rest.getUserNotification(val)
          .subscribe(data => {
            this.notificationList = data;
            if(this.notificationList){
                this.show = true;
            }
            loading.dismissAll();
          }, error => this.errorMessage = <any>error);
      }
    })
  }
  gotoDetails(id) {
    this.navCtrl.push(DetailsPage, {
      id: id
    });
  }

}
